package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygu.common.resulit.Result;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@AllArgsConstructor
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {

     private final HospitalService hospitalService;
     private final DepartmentService departmentService;

    //查询医院列表
    @GetMapping("/findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable int page, @PathVariable int limit, HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitals = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitals);
    }

    //根据医院名称查询
    @GetMapping("/findByHospName/{hospname}")
    public Result findByHospName(@PathVariable String hospname){
        List<Hospital> list = hospitalService.findByHospName(hospname);
        return Result.ok(list);
    }

    //根据医院编号获取科室
    @GetMapping("/department/{hoscode}")
    public Result index(@PathVariable String hoscode){
        List<DepartmentVo> deptTree = departmentService.findDeptTree(hoscode);
        return Result.ok(deptTree);
    }

    //根据医院编号获取医院挂号详情
    @GetMapping("/findHospDetail/{hoscode}")
    public Result item(@PathVariable String hoscode){
        Map<String,Object> map = hospitalService.item(hoscode);
        return Result.ok(map);
    }
}
